package controle;

import java.awt.Frame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;

import presentation.EvalDialog;


import abstraction.Cours;

/** controleur appelé lors de la modification d'une évaluation
 * 
 * @author PICOSSON
 *
 */
public class ControlJButtonEditEval implements Observer, ActionListener {

	private Cours modele;
	private JButton button;
	private Frame parent;

	public ControlJButtonEditEval(Frame parent, Cours modele, JButton button) {
		this.modele = modele;
		this.button = button;
		this.parent = parent;
		button.setEnabled(false);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		EvalDialog evalDialog = new EvalDialog(parent, modele, false);
		evalDialog.setVisible(true);
	}

	@Override
	public void update(Observable o, Object message) {
		Integer iMessage = (Integer) message;
		if (iMessage == Cours.CHANGEMENT_EVALUATION_COURANTE) {
			if (modele.getEvaluationCourante() == -1)
				button.setEnabled(false);
			else
				button.setEnabled(true);
		}
	}

}

